package com.demo.security.access.impl;

import java.util.Collection;
import java.util.List;

import com.demo.security.access.AccessLogicInvocation;
import com.demo.security.access.LogicAttribute;

import org.aopalliance.intercept.MethodInvocation;
import org.springframework.security.core.Authentication;

/**
 * 访问逻辑管理器基本实现类
 * 提供访问逻辑的基本控制
 * 
 * @author ryuu.kk
 *
 */
public class AccessLogicManagerBaseImpl extends AbstractAccessLogicManager<MethodInvocation> {

	/**
	 * 构造函数
	 * @param logicInvocations 访问逻辑调用对象列表
	 */
	public AccessLogicManagerBaseImpl(List<AccessLogicInvocation<MethodInvocation>> logicInvocations) {
		super(logicInvocations);
	}
	
	@Override
	public void access(Authentication authentication, Object object, Collection<LogicAttribute> logicAttributes) {
		
		for (AccessLogicInvocation<MethodInvocation> invoke : getLogicInvocations()) {
			// 取得所有访问逻辑调用对象,进行处理
			if (invoke.supports(object.getClass())) {
				invoke.invoke(authentication, (MethodInvocation) object, logicAttributes);
				if (logger.isDebugEnabled()) {
	                logger.debug("logic : " + invoke + " invoded; ");
	            }
			}
		}
	}
}
